/**
 * SHACrypt header
 *
 * SHACrypt - Encrypt files using cryptographic hash functions
 * Copyright (C) 2010 LlamaSlayers
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @since 1.1.2
 * @version 1.2.2
 */

#ifndef _SHACRYPT_H_
#define _SHACRYPT_H_
// Legacy methods
/** @deprecated */ int SHACrypt_XOR( char *in1, char *in2, char *out, int len );
/** @deprecated */ int SHACrypt_GenKey( char *oldkey, char *newkey, char *password );

int SHACrypt_GenRand( char *data, int len );

// Methods added in the MultiHash branch
#include "third-party/sha1.h"
#include "third-party/sha2.h"
#include "third-party/md5.h"
#include "third-party/cubehash.h"
#include "third-party/nessie.h"

typedef struct SHACrypt_Context {
    // Hash contexts
    SHA1Context sha1;
    sha224_ctx sha224;
    sha256_ctx sha256;
    sha384_ctx sha384;
    sha512_ctx sha512;
    MD5_CTX md5;
    CubeHash_hashState cube;
    NESSIEstruct whirlpool;

    // Hash results
    unsigned char sha1_res[20],
                  sha224_res[28],
                  sha256_res[32],
                  sha384_res[48],
                  sha512_res[64],
                  md5_res[16],
                  cube_res[64],
                  whirlpool_res[64];

    // Hash result pointers
    unsigned char sha1_ptr,
                  sha224_ptr,
                  sha256_ptr,
                  sha384_ptr,
                  sha512_ptr,
                  md5_ptr,
                  cube_ptr,
                  whirlpool_ptr;

    // Scramble hash contexts
    SHA1Context scramble_sha1;
    sha224_ctx scramble_sha224;
    sha256_ctx scramble_sha256;
    sha384_ctx scramble_sha384;
    sha512_ctx scramble_sha512;
    MD5_CTX scramble_md5;
    CubeHash_hashState scramble_cube;
    NESSIEstruct scramble_whirlpool;

    // Scramble hash results
    unsigned char scramble_sha1_res[20],
                  scramble_sha224_res[28],
                  scramble_sha256_res[32],
                  scramble_sha384_res[48],
                  scramble_sha512_res[64],
                  scramble_md5_res[16],
                  scramble_cube_res[64],
                  scramble_whirlpool_res[64];

    // Scramble hash result pointers
    unsigned char scramble_sha1_ptr,
                  scramble_sha224_ptr,
                  scramble_sha256_ptr,
                  scramble_sha384_ptr,
                  scramble_sha512_ptr,
                  scramble_md5_ptr,
                  scramble_cube_ptr,
                  scramble_whirlpool_ptr;

    // Other variables
    unsigned char algos,
                  *password,
                  *scramblekey,
                  *rand;
    unsigned int  passlen,
                  scramblelen,
                  randlen;
} SHACrypt_Context;

int SHACrypt_GetLength( unsigned char algos );
int SHACrypt_GetRand( unsigned char algos, char *rand );
void SHACrypt_Init( SHACrypt_Context *ctx, unsigned char *password, unsigned int passlen,
                    unsigned char algos, unsigned char *rand, unsigned int randlen );
void SHACrypt_Process( SHACrypt_Context *ctx, char *in, char *out, unsigned int len );

// Added in format v3
void SHACrypt_SetScramble( SHACrypt_Context *ctx, unsigned char *code, unsigned int len );
void SHACrypt_Scramble( SHACrypt_Context *ctx, char *in, char *out, unsigned int len );
void SHACrypt_Unscramble( SHACrypt_Context *ctx, char *in, char *out, unsigned int len );
#endif
